package com.zy.yygh.user.api;

import com.zy.yygh.common.result.Result;
import com.zy.yygh.common.utils.AuthContextHolder;
import com.zy.yygh.model.user.UserInfo;
import com.zy.yygh.user.service.UserInfoService;
import com.zy.yygh.vo.user.LoginVo;
import com.zy.yygh.vo.user.UserAuthVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/api/user")
public class UserInfoApiController {
    @Resource
    private UserInfoService userInfoService;

//    用户手机号登录接口
    @PostMapping("login")
    public Result login(@RequestBody LoginVo loginVo){
        Map<String,Object> info=userInfoService.loginUser(loginVo);
        return Result.ok(info);
    }
//    用户认证接口
    @PostMapping("auth/userAuth")
    @ApiOperation(value = "用户认证接口")
    public Result userAuth(@RequestBody UserAuthVo userAuthVo,
                           HttpServletRequest request){
        //传递俩参数，第一个用户id，第二个参数认证数据vo对象

        userInfoService.userAuth(AuthContextHolder.getUserId(request),userAuthVo);

        return Result.ok();
    }
//    获取用户id信息接口
    @GetMapping("auth/getUserInfo")
    public Result getUserInfo(HttpServletRequest request){
        long userId = AuthContextHolder.getUserId(request);
        UserInfo userInfo = userInfoService.getById(userId);
        return Result.ok(userInfo);
    }

}
